package com.flash.InventoryManagement.controller;

import com.flash.GlobalManagement.util.Dbutil;
import com.flash.GlobalManagement.util.TableIdUtil;
import com.flash.GlobalManagement.util.TableNameUtil;
import com.flash.GlobalManagement.util.TableTimeUtil;
import com.flash.InventoryManagement.entity.SecurityAccrualStock;
import com.flash.InventoryManagement.entity.SecurityStock;
import com.flash.InventoryManagement.service.SecurityAccrualStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jr
 * @version 1.0
 * @date 2022/8/26
 */
@Controller
public class SecurityAccrualStockContrller {

    @Resource
    SecurityAccrualStockService securityAccrualStockService;

    @Resource
    Dbutil dbutil;

    @RequestMapping("selectSecurityAccrualStock")
    @ResponseBody
    public Map securityAccrualStock(SecurityAccrualStock securityAccrualStock, int page, int limit){
        System.out.println("查询库存应收应付库存");
        Map map = new HashMap();
        List securityAccrualStocklist = securityAccrualStockService.selectSecurityAccrualStock(securityAccrualStock,page,limit);
        //记录总条数
        int count =securityAccrualStockService.countSecurityStock();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",securityAccrualStocklist);
        return map;
    }

    @RequestMapping("insertSecurityAccrualStock")
    @ResponseBody
    public  String insertSecurityAccrualStock(SecurityAccrualStock securityAccrualStock){
        System.out.println("增加库存应收应付");
        securityAccrualStock.setSecurityAccrualStockId(dbutil.getMaxId3(TableIdUtil.SASID, TableNameUtil.SAS, TableTimeUtil.SASTime,securityAccrualStock.getDateAccrualStock()));

      //  System.out.println(securityAccrualStock.getSecurityAccrualStockId());
        int i = securityAccrualStockService.insertSecurityAccrualStock(securityAccrualStock);
        if (i>0){
            return "增加成功";
        }else {
            return "增加失败";
        }
    }

    @RequestMapping("deleteSecurityAccrualStock")
    @ResponseBody
    public String deleteSecurityAccrualStock(SecurityAccrualStock securityAccrualStock){
      int i =  securityAccrualStockService.deleteSecurityAccrualStock(securityAccrualStock);
        if (i>0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    @RequestMapping("updateSecurityAccrualStock")
    @ResponseBody
    public String updateSecurityAccrualStock(SecurityAccrualStock securityAccrualStock){
        int i =securityAccrualStockService.updateSecurityAccrualStock(securityAccrualStock);
        if (i>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
}
